package com.itheima.web.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.itheima.domain.combat.Option;
import com.itheima.domain.combat.QuestionSoul;
import com.itheima.domain.combat.Questionnaire;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.web.manager.SoulCombatManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class SoulCombatController {
    @Autowired
    private SoulCombatManager soulCombatManager;


    //添加后台的题目
    @PostMapping("/tanhua/addQuestionSoul")
    public Map addQuestion(@RequestBody Map map) {
        String  questionContext = (String) map.get("questionContext");
        String questionnaireLevel = (String) map.get("questionnaireLevel");
        List<String> optionContextAndScoreList = (List<String>) map.get("optionContextAndScoreList");
        soulCombatManager.addQuestion(questionnaireLevel,optionContextAndScoreList,questionContext);
        return null;
    }

    //修改题目
    @PutMapping("/tanhua/updeleteQuestionSoul")
    public Map updateQuestion(@RequestBody Map map) {
        List<Map> optionContextAndScoreList = (List<Map>) map.get("optionContextAndScoreList");
        String  questionContext = (String) map.get("questionContext");
        String questionId = (String) map.get("id");
        soulCombatManager.updateQuestion(questionId,optionContextAndScoreList,questionContext);

        return null;
    }

    //删除题目
    @DeleteMapping("/tanhua/deleteQuestionSoul/{id}")
    public Map deleteQuestion(@PathVariable(value = "id") String questionId) {

        soulCombatManager.deleteQuestion(questionId);
        return null;
    }

    //查询所有的题目
    @GetMapping("/tanhua/findQuestionSoulList")
    public PageBeanVo findQuestionSoul(
            @RequestParam(name = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(name = "pagesize",defaultValue = "10")Integer pageSize,
            @RequestParam(name = "questionnaireId",defaultValue = "0")String questionnaireId
    ) {
        //questionnaireId:问卷级别
        return soulCombatManager.findQuestionSoul(pageNum,pageSize,questionnaireId);
    }
}
